<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form"  :inline="true" :model="form" label-width="140px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="付款单号">
              <el-input v-model="form.id" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="回款单号">
              <el-input v-model="form.repaymentSn" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="手机号">
              <el-input v-model="form.phone" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="医院名称">
              <hospitalList @childfun="childfun" />
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="付款时间">
              <el-date-picker
                v-model="time"
                type="daterange"
                value-format="yyyy-MM-dd HH:mm:ss"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <!-- <el-form-item> -->
            <el-button style="margin-left:60px" type="primary" @click="searchFn">查询</el-button>
            <el-button
              v-if="permissionJson.indexOf('AdminMmkHospitalPaidBackProvider.export') !=-1"
              plain
              type="primary"
              class="el-icon-download"
              @click="exportfun"
            >导出</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div class="listDiv">
      <!-- table列表 -->

      <el-table :data="tableData" class="tableData" style="width: 100%">
        <el-table-column type="index" label="序号" />
        <el-table-column prop="hospitalName" label="医院名称" />
        <el-table-column prop="drawbackSn" label="付款单号" />
         <el-table-column prop="paymentId" label="付款方式" />
        <el-table-column prop="repaymentSn" label="回款单号" />
        <el-table-column prop="username" label="客户姓名" />
        <el-table-column prop="phone" label="客户手机号">
          <template slot-scope="scope">
            <span>{{scope.row.phone | phonereg}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="amount" label="退款金额" />
        <el-table-column prop="backRatio" label="回款比率">
          <template slot-scope="scope">
            <div v-if="scope.row.backRatio">
              {{ scope.row.backRatio }}%
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="backAmount" label="应付款金额" />
        <el-table-column prop="paidAmount" label="实际付款金额" />
        <el-table-column prop="checkedAmount" label="核销金额" />

        <el-table-column prop="paidCard" label="付款银行卡号" />
        <el-table-column prop="remark" label="备注" />
        <el-table-column prop="createdAt" label="付款日期 " />
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="form.pageNum"
            :page-sizes="page_sizes"
            :page-size="form.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import paylist from '@/api/paylist'
import hospitalList from '@/components/hospitalList'
import { exportfile } from '@/api/exporfile'
export default {
  name: 'refundedInfo',
  components: {
    hospitalList
  },
  filters: {
    cardType: function(e) {
      return window.helper.cardType(e)
    },
    // 0为未审核 1为审核通过  2为审核驳回
    RS: function(e) {
      switch (e) {
        case 0:
          return '未审核'
        case 1:
          return '审核通过'
        case 2:
          return '审核驳回'
        default:
          return '暂无'
      }
    }
  },
  data() {
    return {
      time: '',
      tableLoading: true,
      officeOption: [],
      permissionJson: JSON.parse(localStorage.getItem('permissionJson')),
      options: [
        {
          value: '选项1',
          label: '黄金糕'
        }
      ],
      form: {
        repaymentSn: '', // 回款单号
        id: '', // 付款单号
        phone: '', // 手机号
        hospitalId: '', // 医院id
        startTime: '', // 付款时间开始
        endTime: '', // 付款时间结束
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      page_sizes: [10, 30, 50, 100],
      page_totals: 0
    }
  },
  mounted() {
    // //分公司列表
    // this.getCompanyList()
    // if(this.$route.query.userId){
    //     this.form.name = this.$route.query.userId
    // }
    this.getList(this.form)
  },
  methods: {
    // 导出
    exportfun() {
      paylist.expor(this.form).then(res => {
        exportfile(res)
      })
    },
    childfun(res) {
      this.form.hospitalId = res.id + ''
    },
    // 按钮权限
    hasPermission(e) {
      return window.helper.hasPermission(e)
    },
    // 成功状态弹窗
    succStatus(txt) {
      this.$message({
        message: txt + '成功',
        type: 'success'
      })
    },
    // 失败状态弹窗
    errorStatus(txt) {
      this.$message.error(txt + '失败')
    },
    // 查询
    searchFn() {
      this.form.pageNum = 1

      this.form.startTime = this.time ? this.time[0] : ''
      this.form.endTime = this.time ? this.time[1] : ''
      console.log(this.form)
      this.getList(this.form)
    },

    // 列表数据获取
    getList(e) {
      this.tableLoading = true
      const datas = e
      paylist
        .refundeinfo(datas)
        .then(res => {
          // console.log(res)
          if (res.data.code == 0) {
            console.log(res.data.data.list)
            this.tableData = res.data.data.paymentResponseDTOS
            this.page_totals = res.data.data.count
          } else {
            this.$message.error(res.data.msg)
          }
          this.tableLoading = false
        })
        .catch(error => {
          this.$message.error(error)
        })
    },

    // 改变页面条数
    handleSizeChange(val) {
      this.form.pageSize = val
      this.form.pageNum = 1
      this.getList(this.form)
    },
    // 选择页数
    handleCurrentChange(val) {
      this.form.pageNum = val
      this.getList(this.form)
    }
  }
}
</script>

<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
</style>
